package demo2

import "math"

type (
	RoundHole struct {
		radius float64
	}

	RoundPeg struct {
		radius float64
	}

	SquarePeg struct {
		width float64
	}

	Peg interface {
		GetRadius() float64
	}
)

func (rh *RoundHole) fits(peg RoundPeg) bool {
	return rh.radius >= peg.radius
}

func (sp *SquarePeg) getSquare() float64 {
	return math.Pow(sp.width, 2)
}

// 定义方钉到圆孔的适配器
type SquarePegAdapter struct {
	Peg
	peg SquarePeg
}

func (spa SquarePegAdapter) GetRadius() float64 {
	return math.Sqrt(math.Pow(spa.peg.width/2, 2) * 2)
}
